<template>
  <group-component v-if="globalShareItem" :item="globalShareItem" class="wid-hei-inherit global-share-container"></group-component>
</template>
<script>
import { wbBase } from '@/components/utils/wbBase'
import { mapGetters } from 'vuex'
import { defineAsyncComponent } from 'vue'
import { searchComponentDataById } from '@/store/index-utils'

const components = {
  GroupComponent: defineAsyncComponent(() => import('@/components/group-component.vue')),
};

export default {
  mixins: [wbBase],
  components,
  computed: {
    ...mapGetters({
      globalCurrentPage: "getCurrentPage",
    }),
    globalShareItem(){
      let currentPage = this.pages[this.pageIndex];
      let otherGroup = this.isGlobalShareComponents[this.globalCurrentPage.id]
      let components = otherGroup && otherGroup.components;
      let componentData;
      let needGroup = {components:[]};
      if(components) {
        for(let i = 0, len = components.length; i < len; i++) {
          componentData = components[i];
          const componentDataInPage = searchComponentDataById(componentData.id, currentPage);
          if(!componentDataInPage) {
            needGroup.components.push(componentData);
            break;
          }
        }
      }
      return needGroup;
    }
  },
};
</script>
